using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using APPro.Entities;
using APPro.Business;

public partial class Admin_Users_ListUser : System.Web.UI.Page
{
    UserCollection user = null;

    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        UsersListRepeater.ItemDataBound += new RepeaterItemEventHandler(UsersListRepeater_ItemDataBound);
        UsersListRepeater.ItemCommand += new RepeaterCommandEventHandler(UsersListRepeater_ItemCommand);

        UserListPager.Parameter = "CurrentPage";
        UserListPager.PageSize = 10;
    }

    void UsersListRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        
    }

    void UsersListRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            User user = e.Item.DataItem as User;
            if (user != null)
            {
                Literal userNameLiteral = e.Item.FindControl("UserNameLiteral") as Literal;
                userNameLiteral.Text = HttpUtility.HtmlEncode(user.Ten);

                HtmlAnchor emailLink = e.Item.FindControl("emailLink") as HtmlAnchor;
                emailLink.InnerHtml = HttpUtility.HtmlEncode(user.Email);
                emailLink.HRef = string.Format("mailto:{0}", user.Email);

                HtmlAnchor EditLink = e.Item.FindControl("EditLink") as HtmlAnchor;
                EditLink.HRef = string.Format("~/{0}?{1}={2}",
                    SitePages.BO_EditUser,
                    "UserID",
                    user.MaSoCaNhan);

                ImageButton DeleteLink = e.Item.FindControl("DeleteLink") as ImageButton;
                DeleteLink.CommandArgument = user.MaSoCaNhan.ToString();
            }
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            LoadData();
            UpdateView();
        }
    }

    private void LoadData()
    {
        int totalRecord = 0;
        this.user = UserService.GetUserList(UserColumns.Ten, Pyco.Data.OrderDirection.DESC,
            UserListPager.PageIndex + 1,
            UserListPager.PageSize,
            out totalRecord);
        UserListPager.TotalRecords = totalRecord;
    }

    private void UpdateView()
    {
        UsersListRepeater.DataSource = this.user;
        UsersListRepeater.DataBind();
    }

}
